<template>
	<view>
		<utop :istype="1"></utop>
		<view class="" v-if="ishide">
			<view class="kongs" v-if="isshow">
				<view class="">
					<image src="../../static/kongs.png" mode=""></image>
					<view class="tss">
						<span>吸塑</span> 工作未结束，暂不可操作
					</view>
				</view>
			</view>
			<scroll-view scroll-y="true" style="height: 100vh;" 
			:refresher-enabled='true' :refresher-threshold='30' refresher-background='#F7F8FA'
			 @refresherrefresh='refresherrefresh' :refresher-triggered='isdown'>
			 <view class="" v-if="!isshow">
			 	<view class="content">
			 		<view class="flex_bet items">
			 			<view class="textLeft">规格型号</view>
			 			<view class="rightbt">{{orderinfo.xinghao_name?orderinfo.xinghao_name:""}}
							{{orderinfo.color_name?orderinfo.color_name:''}}</view>
			 		</view>
			 		<view class="flex_bet items">
			 			<view class="textLeft">理论片数</view>
			 			<view class="" style="font-weight: bold;">{{num}}</view>
			 		</view>
			 		<view class="flex_bet items">
			 			<view class="textLeft">制作片数</view>
			 			<view class="rightinput">
			 				<!-- @confirm="handleLogin" -->
			 				<input placeholder-class="ustyle" v-model="nownum" type="number" placeholder="请输入" />
			 			</view>
			 		</view>
			 		<view class="btnlist">
			 			<view class="btn b1" @click="handleBf">部分完成</view>
			 			<view class="btn b2" @click="handleAll">全部完成</view>
			 		</view>
			 	</view>
			 	<view class="footer">
			 		<view class="utitle" v-if="!nolist">总计报工数量：{{allNum}}</view>
			 		<scroll-view class="clist" scroll-y="true" style="height: 45vh;" :show-scrollbar='false'
			 			@scrolltolower='onbottom'>
			 			<view class="" v-for="(item,index) in ulist" :key="index" style="margin-bottom: 20rpx;">
			 				<view class="ut flex_bet">
			 					<view class="t1">报工数量</view>
			 					<view class="t2">{{item.num}}</view>
			 				</view>
			 				<view class="utexts">
			 					<view class="">报工人：{{item.user_name}}</view>
			 					<view class="">报工时间：{{item.updatetime | formatDate}}</view>
			 					<view class="">报工数量：{{item.num}}</view>
			 					<view class="">报工单位：{{item.unit}}</view>
			 				</view>
			 			</view>
			 			<uni-load-more v-if="!ulist.length <= 0" :status="statusshow"></uni-load-more>
			 			<view class="" v-if="nolist">
			 				<view class="textLeft">报工记录</view>
			 				<view class="imgs">
			 					<image src="../../static/k.png" mode=""></image>
			 					<view class="ts">
			 						暂无报工明细
			 					</view>
			 				</view>
			 			</view>
			 		</scroll-view>
			 	</view>
			 </view>
		</scroll-view>
			
		</view>
		

		<uni-popup ref="popups" type="center">
			<view class="popup1">
				<!-- 第一次报工 -->
				<view class="">
					<uni-icons @click="close(2)" color="#979797" size="24" class="icon" type="closeempty"></uni-icons>
					<view class="img">
						<image src="../../static/info.png" mode=""></image>
					</view>
					<view class="texts">
						<view class="" v-if="ulist.length ==0 && isall == 2 ">
							此次部分完成报工数量：<span style="color: #196AEB;">{{nownum}}</span>
						</view>
						<view class="" v-else>
							<view class="" v-if="ulist.length !=0">
								已经报工数量：<span>{{allNum}}</span>
							</view>
							<view class="">
								此次报工数量：<span style="color: #196AEB;">{{nownum}}</span>
							</view>
							<view class="">
								总计报工数量：<span>{{Number(allNum)+Number(nownum)}}</span>
							</view>
						</view>
					</view>
					<view class="context" v-if="isall == 1">
						是否确认<span style="color: #196AEB;">全部报工</span>已完成？
					</view>
					<view class="context" v-if="isall == 2">
						是否确认<span style="color: #196AEB;">部分报工</span>已完成？
					</view>
					<view class="bnts">
						<view class="btn b1" @click="close(2)">
							取消
						</view>
						<view class="btn b2" @click="handleTj">
							确认提交
						</view>
					</view>
				</view>
				<!-- 多次报工 -->
			</view>
		</uni-popup>
		<uni-popup ref="popupYes" type="center" :is-mask-click="false">
			<view class="yes">
				<view class="img">
					<image src="../../static/yes.png" mode=""></image>
				</view>
				<view class="ts">
					您已提交此订单全部完成，不支持再操作
				</view>
				<view class="" style="display: flex;align-items: center;">
					<view class="btn" @click="goi">
						首页
					</view>
					<view class="btn" @click="goindex">
						扫描新订单
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getOrderInfo,
		getOrderboard,
		getOrderLogList,
		setyuanmoWork
	} from '@/common/http.api.js'
	export default {
		data() {
			return {
				ishide: false,
				isdown:true,
				isshow: false,
				num: 0,
				nownum: '',
				isall: 1,
				ulist: [],


				orderinfo: {},
				params: {
					order_id: 6,
					page: 1,
					limit: 10
				},
				tjparams: {
					order_id: 6,
					num: '', //数量
					finish_type: '', //类型
				},
				statusshow: 'loading',
				nolist: true,
				isnoopen: false,
				order_id: 6,
				allNum:0,
				userInfo:uni.getStorageSync('userinfo')
			};
		},
		onLoad(option) {
			this.order_id = option.id
			this.params.order_id = option.id
			this.tjparams.order_id = option.id
			this.getOrderInfoFun()
			this.getOrderlist()
		},
		methods: {
			goi(){
				uni.redirectTo({
					url:'/pages/index/index'
				})
			},
			refresherrefresh(e){
				this.isdown = true
				this.ulist= []
				this.getOrderInfoFun()
				this.getOrderlist()
				setTimeout(()=>{
					this.isdown = false
					uni.showToast({
						icon:'none',
						title:'数据已更新'
					})
				},1000)
			},
			getOrderInfoFun() {
				getOrderInfo({
					order_id: this.order_id
				}).then(res => {
					this.orderinfo = res.data
					this.num = res.data.lilun_num
					this.allNum = res.data.yuanmo_finish_num
					if (res.data.status < 4) {
						this.isshow = true
						this.ishide = true
					} else if(res.data.status >=6) {
						this.ishide = false
						this.$refs.popupYes.open()
					}else{
						this.ishide = true
						this.isshow = false
					}
				})
			},
			getOrderlist() {
				this.statusshow = 'loading'
				getOrderLogList(this.params).then(res => {
					if (res.code == 1) {
						this.ulist.push(...res.data.list)
						this.statusshow = 'no-more'
						let total = Math.ceil(res.data.total_page / this.params.limit);
						this.nolist = total == 0
					}
				})
			},
			onbottom() {
				this.params.page++
				this.getOrderlist()
			},
			goindex() {
				let that = this
				uni.scanCode({
					barCodeInput: true,
					onlyFromCamera: true,
					success: function(res) {
						if (res.errMsg == "scanCode:ok") {
				            let id = res.path.substring( res.path.lastIndexOf('?') + 1,res.path.length).substring(9)
						    setTimeout(()=>{
							   that.handleSm(id)
							   that.$refs.popupYes.close()
						    },500)
						}
					},
				})
			},
			handleSm(id) {
				if(this.userInfo.type == 1){
					uni.redirectTo({
						url:`/pages/index/xspage?id=${id}`
					})
				}
				if(this.userInfo.type == 2){
					uni.redirectTo({
						url:`/pages/index/ympage?id=${id}`
					})
				}
				if(this.userInfo.type == 3){
					uni.redirectTo({
						url:`/pages/index/xppage?id=${id}`
					})
				}
				if(this.userInfo.type == 4){
					uni.redirectTo({
						url:`/pages/index/xzpage?id=${id}`
					})
				}
			
			},
			close(type) {
				if (type == 1) {
					this.$refs.popup.close()
				} else {
					this.$refs.popups.close()
				}
			},
			handleBf() {
				if (this.nownum == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入制作片数'
					})
					return
				}
				this.tjparams.finish_type = 1
				this.isall = 2
				this.$refs.popups.open()
			},
			handleAll() {
				if (this.nownum == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入制作片数'
					})
					return
				}
				this.tjparams.finish_type = 2
				this.isall = 1
				this.$refs.popups.open()
			},
			//点击提交按钮
			handleTj() {
				this.tjparams.num = this.nownum
				setyuanmoWork(this.tjparams).then(res => {
					if (res.code == 1) {
						this.params.page = 1
						getOrderLogList(this.params).then(res => {
							if (res.code == 1) {
								this.ulist = res.data.list
								this.statusshow = 'no-more'
								let total = Math.ceil(res.data.total_page / this.params.limit);
								this.nolist = total == 0
								this.nownum = ''
								this.$refs.popups.close()
								this.getOrderInfoFun()
								if (this.tjparams.finish_type == 2) {
									this.$refs.popupYes.open()
								}
							}
						})

					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.ustyle {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #979797;
	}

	.kongs {
		margin: 240rpx auto;
		display: flex;
		justify-content: center;

		image {
			width: 400rpx;
			height: 324rpx;
		}

		.tss {
			margin-top: 100rpx;
			font-family: PingFang SC, PingFang SC;
			font-size: 32rpx;
			color: #979797;

			span {
				font-weight: bold;
				color: #196AEB;
			}
		}
	}

	.content {
		background-color: #F7F8FA;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.items {
		width: 710rpx;
		height: 120rpx;
		background: #FFFFFF;
		border-radius: 22rpx;
		padding: 34rpx 30rpx 34rpx 44rpx;
		box-sizing: border-box;
		margin: 0rpx auto 20rpx;

		.rightbt {
			height: 60rpx;
			background: #F2F8FF;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			border: 1rpx solid #196AEB;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #196AEB;
			line-height: 60rpx;
			text-align: center;
			padding: 0rpx 10rpx;
		}

		.rightinput {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			flex: 1;

			input {
				font-family: DIN, DIN;
				font-weight: bold;
				font-size: 40rpx;
				color: #196AEB;
				text-align: right;
			}
		}
	}

	.item_flex {
		width: 710rpx;
		margin: 20rpx auto;

		.itemss {
			width: 350rpx;
			height: 200rpx;
			background: #FFFFFF;
			border-radius: 22rpx;
			padding: 34rpx 44rpx;
			box-sizing: border-box;

			.imgflex {
				margin-top: 28rpx;
				display: flex;
				align-items: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #979797;

				image {
					width: 22rpx;
					height: 26rpx;
					margin-left: 20rpx;
				}
			}

			.imgflex1 {
				margin-top: 28rpx;
				font-family: DIN, DIN;
				font-weight: bold;
				font-size: 40rpx;
				color: #000000;

				span {
					font-size: 30rpx;
					margin-left: 6rpx;
				}
			}

			.imgflex2 {
				font-family: DIN, DIN;
				font-weight: bold;
				font-size: 40rpx;
				color: #196AEB;
			}
		}
	}

	.btnlist {
		width: 710rpx;
		display: flex;
		justify-content: space-between;
		margin: 20rpx auto 0rpx;

		.btn {
			width: 350rpx;
			height: 90rpx;
			border-radius: 50rpx 50rpx 50rpx 50rpx;
			text-align: center;
			line-height: 90rpx;
		}

		.b1 {
			border: 1rpx solid #196AEB;
			background-color: #FFFFFF;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #196AEB;
		}

		.b2 {
			background: #196AEB;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #ffffff;
		}
	}

	.footer {
		width: 100%;
		background-color: #FFFFFF;
		padding: 34rpx 32rpx;
		box-sizing: border-box;

		.imgs {
			text-align: center;

			image {
				display: block;
				margin: 80rpx auto 30rpx;
				width: 482rpx;
				height: 340rpx;
			}

			.ts {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #979797;
			}
		}

		.utitle {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 40rpx;
			color: #000000;
			line-height: 47rpx;
			width: 100%;
			margin-bottom: 30rpx;
		}

		.clist {
			.ut {
				border-top: 1px solid #D1D1D6;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 36rpx;
				padding-top: 32rpx;

				.t1 {
					color: #1D2541;
				}

				.t2 {
					color: #196AEB;
				}
			}

			.utexts {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #808080;
				line-height: 46rpx;
				margin-top: 10rpx;
			}
		}

	}

	.popup1 {
		background-color: #FFFFFF;
		width: 600rpx;
		border-radius: 30rpx;
		padding: 56rpx 30rpx;
		box-sizing: border-box;
		text-align: center;

		.icon {
			top: 28rpx;
			right: 40rpx;
			position: absolute;
		}

		.img {
			width: 152rpx;
			height: 152rpx;
			margin: 0rpx auto;

			image {
				width: 152rpx;
				height: 152rpx;
			}
		}

		.texts {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #666666;
			margin: 34rpx auto 40rpx;

			span {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
			}
		}

		.context {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #333333;
			line-height: 35rpx;
		}

		.bnts {
			display: flex;
			margin-top: 36rpx;
			justify-content: space-between;

			.btn {
				width: 250rpx;
				height: 80rpx;
				background: #FFFFFF;
				border-radius: 40rpx;
				line-height: 80rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
			}

			.b1 {
				border: 1rpx solid #979797;
				color: #979797;
			}

			.b2 {
				background: #196AEB;
				color: #FFFFFF;
			}
		}
	}

	.yes {
		background-color: #FFFFFF;
		width: 600rpx;
		border-radius: 30rpx;
		padding: 56rpx 30rpx;
		box-sizing: border-box;
		text-align: center;

		.img {
			width: 152rpx;
			height: 152rpx;
			margin: 0rpx auto;

			image {
				width: 152rpx;
				height: 152rpx;
			}
		}

		.ts {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #333333;
			margin-top: 20rpx;
		}

		.btn {
			height: 80rpx;
			background: #196AEB;
			border-radius: 40rpx;
			margin: 60rpx auto 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #FFFFFF;
			line-height: 80rpx;
			text-align: center;
			padding: 0rpx 60rpx;
		}
	}
</style>